﻿using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using XnReader.WinRT.Forms;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace XnReader.WinRT
{
    public sealed partial class Navigation : UserControl
    {
        public Navigation()
        {
            InitializeComponent();

            var navCls = new Nav();
            var leftNavs = navCls.GetLeftNavs();
            cvsLeft.Source = leftNavs;
            var rightNavs = navCls.GetRightNavs();
            cvsRight.Source = rightNavs;
        }

        private void GvLeftNavsItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem != null)
            {
                var nav = e.ClickedItem as Nav;
                if (nav != null)
                {
                    var rootFrame = Window.Current.Content as Frame;
                    if (nav.Id < 1000)
                    {
                        if (rootFrame != null) rootFrame.Navigate(typeof (BookList), nav.Id);
                    }
                    else
                    {
                        if (rootFrame != null) rootFrame.Navigate(typeof (OnlineStore), nav.Id);
                    }
                }
            }
        }

        private void GvRightNavsItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem != null)
            {
                var nav = e.ClickedItem as Nav;
                if (nav != null)
                {
                    var rootFrame = Window.Current.Content as Frame;
                    if (rootFrame != null)
                    {
                        //rootFrame.Navigate(typeof (BookStore), nav.Id);
                        rootFrame.Navigate(typeof(Bookcase));
                    }
                }
            }
        }
    }

    public class Nav
    {
        public int Id { get; set; }

        public string Title { get; set; }

        public string Tips { get; set; }

        //public SolidColorBrush BackColor { get; set; }

        //public BitmapImage Image { get; set; }
        public string Image { get; set; }

        public IList<Nav> GetLeftNavs()
        {
            IList<Nav> list = new List<Nav>();
            var nav0 = new Nav
            {
                Id = 1001,
                Title = "首页",
                Tips = "首页",
                Image = "⛺"
                //Image = new BitmapImage(new Uri("ms-appx:///Assets/nav/quanben.png"))
            };
            list.Add(nav0);
            var nav1 = new Nav
            {
                Id = 101,
                Title = "全本",
                Tips = "全本阅读",
                Image = "❁"
                //Image = new BitmapImage(new Uri("ms-appx:///Assets/nav/quanben.png"))
            };
            list.Add(nav1);
            var nav2 = new Nav
            {
                Id = 1,
                Title = "玄幻",
                Tips = "玄幻奇幻",
                Image = "✡"
            };
            list.Add(nav2);
            var nav3 = new Nav
            {
                Id = 2,
                Title = "武侠",
                Tips = "武侠仙侠",
                Image = "☯"
            };
            list.Add(nav3);
            var nav4 = new Nav
            {
                Id = 3,
                Title = "言情",
                Tips = "都市言情",
                Image = "⚭"
            };
            list.Add(nav4);
            var nav5 = new Nav
            {
                Id = 4,
                Title = "军事",
                Tips = "历史军事",
                Image = "☭"
            };
            list.Add(nav5);
            var nav6 = new Nav
            {
                Id = 5,
                Title = "游戏",
                Tips = "游戏竞技",
                Image = "⚽"
            };
            list.Add(nav6);
            var nav7 = new Nav
            {
                Id = 6,
                Title = "科幻",
                Tips = "科幻灵异",
                Image = "⚛"
            };
            list.Add(nav7);
            var nav8 = new Nav
            {
                Id = 7,
                Title = "同人",
                Tips = "漫画同人",
                Image = "⚘"
            };
            list.Add(nav8);
            return list;
        }

        public IList<Nav> GetRightNavs()
        {
            IList<Nav> list = new List<Nav>();
            var nav1 = new Nav
            {
                Id = 1,
                Title = "我的书架",
                Image = "☷"
            };
            list.Add(nav1);
            //var nav2 = new Nav
            //{
            //    Id = 2,
            //    Title = "离线缓存",
            //    Image = "⟱"
            //};
            //list.Add(nav2);
            //var nav3 = new Nav
            //{
            //    Id = 3,
            //    Title = "阅读历史",
            //    Image = "❁"
            //};
            //list.Add(nav3);
            return list;
        }
    }
}
